import 'dart:async';

Future<String> lookUpVersion() async {
  await Future.delayed(Duration(seconds: 1));
  return "1.0.0";
  
}


Future<void> checkVersion() async {
  var version = await lookUpVersion();
  print("��ǰ�汾��: $version");
}

Future<String> findEntryPoint() async {
  await Future.delayed(Duration(seconds: 1));
  return 'example_entrypoint';
}


Future<int> runExecutable(String entrypoint, List<String> args) async {
  await Future.delayed(Duration(seconds: 1));
  return 0;
}

Future<void> flushThenExit(int exitCode) async {
  await Future.delayed(Duration(seconds: 1));
  print('Exiting with code: $exitCode');
}

void handleRequest(dynamic request) {
  print('���ڴ�������: $request');
}
void main(List<String> args) async {
  var entrypoint = await findEntryPoint();
  var exitCode = await runExecutable(entrypoint, args);
  await flushThenExit(exitCode);

  await checkVersion();
  print('In main: version is ${await lookUpVersion()}');
  try {
  var version = await lookUpVersion();
  } catch (e) {
  // React to inability to look up the version

//https://dart.cn/language/async/#handling-streams

  Stream<int> stream = Stream.periodic(Duration(seconds: 1), (count) => count);

  await for (int value in stream.take(5)) {
    print('���յ���ֵ: $value');
  }

  print('����������');



  StreamController<dynamic> requestServerController = StreamController();
  Stream<dynamic> requestServer = requestServerController.stream;


  Timer.periodic(Duration(seconds: 1), (timer) {
    if (timer.tick <= 5) {
      requestServerController.add('���� ${timer.tick}');
    } else {
      timer.cancel();
      requestServerController.close();
    }
  });


  await for (final request in requestServer) {
    handleRequest(request);
  }

  print('�������������');
}
 
}
 void my_Declaring(){
  //https://dart.cn/language/async/#declaring-async-functions
 String lookUpVersion1() => '1.0.0';
 Future<String> lookUpVersion() async => '1.0.0';

 }
